import { createSlice, PayloadAction } from "@reduxjs/toolkit";
export type userinfoType = {
  username: string;
  nickname: string;
};

const initialUserInfo: userinfoType = { username: "", nickname: "" };

const userInfoSlice = createSlice({
  name: "userInfoSlice",
  initialState: initialUserInfo,
  reducers: {
    setUserInfo_reducer(state: userinfoType, action: PayloadAction<userinfoType>) {
      state = action.payload;
      return { ...state };
    },
    resetUserInfo_reducer(state) {
      return initialUserInfo;
    },
  },
});

export const { setUserInfo_reducer, resetUserInfo_reducer } = userInfoSlice.actions;

export default userInfoSlice.reducer;
